package com.graduation.books_borrow.repository;

import com.graduation.books_borrow.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {

    @Insert("insert into user(username, password, status, addtime) values(#{username}, #{password}, #{status}, #{addtime})")
    boolean addUser(User user);

    @Select("select id, username, password, status, addtime from user where username=#{username} and status = 1 limit 1")
    User selectUserByName(User user);

    @Select("select id, username, password, status, addtime from user where username=#{username} and password=#{password} and status = 1 limit 1")
    User selectUserByNamePsw(User user);

    @Select("select id, username, password, status, addtime from user where id=#{id} and status = 1 limit 1")
    User selectUserByUserId(User user);

    @Select("select id, username, password, status, addtime from user where status = 1")
    List<User> selectUser();

    @Update("update user set status = 0 where username = #{username}")
    int updateUser(User user);

}
